package com.cindata

import com.cindata.api.ApiService
import com.cindata.api.EvaluationApiService

class EvaluateThreadService implements Runnable
{

    def apiService
    def evaluationApiService
    private EstateImport bean
    def evaluateService

    public EvaluateThreadService(EstateImport estateImport, ApiService apiService, EvaluationApiService evaluationApiService, EvaluateService evaluateService)
    {
        this.bean = estateImport
        this.apiService = apiService
        this.evaluationApiService = evaluationApiService
        this.evaluateService = evaluateService
    }

    @Override
    void run()
    {
        def batch = bean.getBatch()
        def param = [em: 7,
            batchNum: batch.id,
            batchTotalCount: batch.getBatchNumber(),
            batchLevel: '户',
            city: bean.getCityName(),
            address: bean.getAddress(),
            floor: bean.getCurrentFloor(),
            totalFloor: bean.getTotalFloor(),
            square: bean.getBuildArea()]
        def result
        if (param.em == 7)
        {
            result = evaluationApiService.manualEvaluation(param)
        }
        else
        {
            result = apiService.evaluate(param)
        }
        // 创建计费数据
        UserCost.CreateByEstateEvaluate(bean.getBatch().id, bean)
        if (result)
        {
            evaluateService.evaluateCallBack(this.bean, result)
        }
    }
}
